package com.demo13;

import java.util.Comparator;
import java.util.TreeSet;

public class HumanDemo1 {
    public static void main(String[] args) {
        //安装身高体重进行排序操作
        //实例化Treeset信息 用comparartor操作
        TreeSet<Human> humanTreeSet = new TreeSet<Human>(new Comparator<Human>() {
            @Override
            //多条件重写计算方法。
            public int compare(Human h1, Human h2) {
                //主要条件
                int num = (int)(h1.getScore() - h2.getScore());
                //附加条件
                int num1 = num==0 ? (int)(h1.getHeight() - h2.getHeight()) : num;
                int num2 = num1==0 ? h1.getName().compareTo(h2.getName()) : num1;
                return num2;
            }
        });

        //实例化对象的类
        Human h1 = new Human("Kobe", 198, 102);
        Human h2 = new Human("詹姆斯", 206, 114);
        Human h3 = new Human("姚明", 226, 94);
        Human h4 = new Human("Mark", 198, 102);

        //增加对象信息
        humanTreeSet.add(h1);
        humanTreeSet.add(h2);
        humanTreeSet.add(h3);
        humanTreeSet.add(h4);
        //循环操作
        for (Human h: humanTreeSet){
            System.out.println(h.getName()+",身高:"+h.getHeight()+",体重:"+h.getWeight()+",综合:"+h.getScore());
        }
    }
}
